package com.china.great.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.china.great.common.common.CommonResultUtil;
import com.china.great.system.entity.SystemUser;
import com.china.great.system.service.SystemUserService;
import com.china.great.system.util.JwtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: Liu HongYang
 * @DateTime: 2020/7/13 10:31 下午
 * @Description: TODO
 */
@RestController
@Api("用户相关的api")
@RequestMapping("/system/user")
public class SystemUserController {


    @Value("${jwt.header}")
    private String token_header;

    @Resource
    private JwtUtils jwtUtils;

    @Autowired
    private SystemUserService systemUserService;

    @RequestMapping(value = "/getList", method = RequestMethod.GET)
    @ApiOperation(value="获取列表")
    public Object getList(@RequestParam(value="pageSize", defaultValue="20") int pageSize,
                          @RequestParam(value="pageNum", defaultValue="1") int pageNum) {
        Page<SystemUser> page = new Page<>(1, 3);//参数一是当前页，参数二是每页个数
        IPage iPage = systemUserService.getPageUserList(page);
        return CommonResultUtil.success(iPage);
    }

    @RequestMapping(value = "/getUserInfo", method = RequestMethod.GET)
    @ApiOperation(value="根据token获取用户详情")
    public Object getUserByToken() {
        SystemUser userDetail = jwtUtils.getUserFromToken(token_header);
        return CommonResultUtil.success(userDetail);
    }

}
